<!DOCTYPE html>
<html class="um landscape min-width-240px min-width-320px min-width-480px min-width-768px min-width-1024px">
    <head>
        <title></title>
        <meta charset="utf-8">
        <meta name="viewport" content="target-densitydpi=device-dpi, width=device-width, initial-scale=1, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
        <link rel="stylesheet" href="css/fonts/font-awesome.min.css">
        <link rel="stylesheet" href="css/ui-box.css">
        <link rel="stylesheet" href="css/ui-base.css">
        <link rel="stylesheet" href="css/ui-color.css">
        <link rel="stylesheet" href="css/appcan.icon.css">
        <link rel="stylesheet" href="css/appcan.control.css">
        <link rel="stylesheet" href="index/css/main.css">
    </head>
    <body class="um-vp bc-bg" ontouchstart>
        <div id="page_0" class="up ub ub-ver" tabindex="0">
            <!--header开始-->
            <div id="header" class="bc-text-head ub bc-head">
                <div class="uh bc-text-head ub bc-head" id="header1">
                    <div class="nav-btn" id="nav-left">
                    </div>
                    <h1 class="ut ub-f1 ulev-3 ut-s tx-c" tabindex="0">飞哥传书</h1>
                    <div class="nav-btn nav-bt" id="nav-right">
                        <div class="fa  fa-cog ulev2"></div>
                    </div>
                </div>

                <div class="uhide" id="header2">
                <h1 class="ut ub-f1 ulev-3 ut-s tx-c" tabindex="0">卖书</h1>
                </div>
                <div class="uhide" id="header3">
                    <div class="nav-btn" id="nav-left">
                        <div class="t-btn-a1 ub-img uwh-tBtn"></div>
                    </div>
                    <h1 class="ut ub-f1 ulev-3 ut-s tx-c" tabindex="0">我的账户</h1>
                    <div class="nav-btn nav-bt" id="nav-right">
                        <div class="t-btn-ds1 ub-img uwh-tBtn"></div>
                    </div>
                </div>
            </div>
            <!--header结束--><!--content开始-->
            <div id="content" class="ub-f1 tx-l t-bla">

            </div>
            <!--content结束--><!--footer开始-->
            <div id="footer" class="uf t-bla ub ubt b-gra4">
                <div class="ub ub-f1 tab" id="footer1">
                    
                </div>
            </div>
            <!--footer结束-->
        </div>
    </body>
    <script src="js/appcan.js"></script>
    <script src="js/appcan.control.js"></script>
    <script src="js/appcan.tab.js"></script>
    </body>
    <script>
        var titHeight = 0;
        var conArray = [false, false, false];
        var arrData = [];
        function init_building(buildings)
        {
            var len = buildings.length;
            for(var i = 0; i < len; ++i)
            {
                arrData.push({
                    "title" : buildings[i].name,
                    "id" : buildings[i].id,
                    "louzhang" : buildings[i].louzhang,
                });
                //alert(buildings[i].id + buildings[i].name + buildings[i].louzhang);
            }
            localStorage.setItem('buildings',arrData);
        }
        
        appcan.ready(function() {
            var request = appcan.require('request');
            request.ajax({
                type : 'POST',
                url : 'http://whynothappy.sinaapp.com/get_buildings',
                data : {},
                contentType: 'application/json',
                success:function(data){
                    //alert(data);
                    data = eval("(" + data + ")");
                    if (data.state == 0)
                    {
                        init_building(data.buildings);
                        sortList();
                    }
                },
                error:function(){
                    alert("fuck");
                }
            })
            
            localStorage.setItem('HasSearch', 0);
            var titHeight = $('#header').offset().height;
            //appcan.frame.open("content", "index_content.html", 0, titHeight);
            openCon(0);
            conArray[0]=true;
            window.onorientationchange = window.onresize = function() {
                appcan.frame.resize("content", 0, titHeight);
            }
        });
        var tabview = appcan.tab({
            selector : "#footer1",
            hasIcon : true,
            hasAnim : false,
            hasLabel : true,
            hasBadge : true,
            index : 0,
            data : [{
                label : "首页",
                icon : "fa-home"
            }, {
                label : "卖书",
                icon : "fa-list"
            }, {
                label : "我",
                icon : "fa-user"
            }]
        });
        tabview.on("click", function(obj, index) {
            openCon(index);
        })
        appcan.button(".nav-btn", "btn-act", function() {
            //appcan.window.close(-1);
        })
        function openCon(idx) {
            var arr = ["index_content.html","sell_content.html","info_content.html"];
            var login = localStorage.getItem('login');
            if (idx == 2 && login != 1 && login != 2) {
                appcan.openWinWithUrl('catalog', 'login_content.html', '0');
                //return;
                openCon(0);
                return;
            }
            if (idx == 2 && login == 2)
            {
                appcan.openWinWithUrl('catalog', 'postman.html');
                return;
            }
            for (var i = 0, l = $("#header")[0].children.length; i < l; i++) {
                if (idx == i) {
                    $("#header")[0].children[i].className = "uh bc-text-head ub bc-head maxh";
                    if (!conArray[idx]) {
                        appcan.openPopoverByEle("content", arr[idx], 0, $('#header').offset().height, 0, 'content_' + idx);
                        appcan.frame.resize("content", 0, $("#header").offset().height, 0, 'content_' + idx); 
                        conArray[idx] = true;
                    } else {
                        appcan.bringPopoverToFront('content_' + idx);
                    }
                } else {
                    $("#header")[0].children[i].className = "uhide";
                }
            }
            //appcan.frame.resize("content", 0, $('#header1').offset().height);
        }
    </script>
</html>
